package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @author 宋鑫宇
 * @version 1.0
 * ---------发送端------
 */
public class ClientDemo1 {
    public static void main(String[] args) throws Exception{
        //1.创建发送端对象
        DatagramSocket socket = new DatagramSocket();

        //2.创建一个数据包对象封装数据
        /*
            public DatagramPacket(byte buf[], int length,InetAddress address, int port)
                                 封装要发送的数据,发送数据大小,服务端IP地址,        目的端口号
         */
        byte[] buf = "一汽奥迪".getBytes();
        DatagramPacket packet = new DatagramPacket(buf,buf.length, InetAddress.getByName("127.0.0.1"),8888);

        //3.发出数据
        socket.send(packet);

        //4.关闭管道释放资源
        socket.close();
    }
}
